@echo off

REM Configure UTF-8 encoding
chcp 65001 > nul

REM Create Python virtual environment
echo Creating Python virtual environment...
python -m venv venv

REM Activate virtual environment
echo Activating virtual environment...
call venv\Scripts\activate.bat

REM Install necessary dependencies
echo Installing dependencies...
pip install --upgrade pip
pip install pandas numpy openpyxl xlrd pyinstaller

REM Package Python script to executable
echo Packaging Python script...
pyinstaller --onefile --windowed --icon=none --name="ExcelSearchTool" --add-data="excel_search_tool.py;." excel_search_tool.py

REM Copy generated exe to current directory
echo Copying executable to current directory...
copy /Y dist\ExcelSearchTool.exe .\

REM Clean temporary files
echo Cleaning temporary files...
rd /s /q build
erd /s /q dist
erd /s /q __pycache__
del /q ExcelSearchTool.spec

REM Deactivate virtual environment
echo Deactivating virtual environment...
call venv\Scripts\deactivate.bat

REM Completion message
echo.
echo Packaging completed!
echo Executable file "ExcelSearchTool.exe" has been generated in the current directory.
echo Press any key to exit...
pause > nul